import numpy as np

# 定义DCT变换大小 得到14组，每组24个DCT变换系数
N = 15
M = 24

# 创建一个矩阵来保存余弦值
cos_table = np.zeros((N, M))

# 计算余弦值
for n in range(1,N):
    for m in range(M):
        cos_table[n, m] = np.cos(np.pi * ( m - 0.5) * n / M)

# # 归一化因子
# alpha = np.sqrt(1/N) if n == 0 else np.sqrt(2/N)

# # 应用归一化因子
# cos_table *= alpha

# 量化查找表
bits = 16  # 量化位数
int_max = (2**(bits - 1)) - 1
cos_table_q = np.round(cos_table * int_max).astype(int)

# 将查找表写入文件
with open('DCT_LUT.txt', 'w') as file:
    file.write(f'{bits}\n')  # 写入量化位数
    for row in cos_table_q:
        line = ' '.join(map(str, row))
        file.write(line + '\n')